using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    public InputField userInputField;
    public InputField passwordInputField;
    public InputField passwordRetypeInputField;

    public Button registerButton;
    public Button loginButton;
    public Button goLoginButton;
    public Button goRegisterButton;

    public Text contentText;

    public static UIManager Instance { get; private set; }

    private void RefreshInputField()
    {
        userInputField.text = "";
        passwordInputField.text = "";
        passwordRetypeInputField.text = "";
    }
    private void Start()
    {
        Instance = this;
        NetworkManager.Connect();

        loginButton.gameObject.SetActive(false);
        goRegisterButton.gameObject.SetActive(false);

        registerButton.onClick.AddListener(() =>
        {
            if (passwordInputField.text != passwordRetypeInputField.text)
                return;
            NetworkManager.Send("Register|" + userInputField.text + "|" + passwordInputField.text);
            RefreshInputField();
        });
        loginButton.onClick.AddListener(() =>
        {
            NetworkManager.Send("Login|" + userInputField.text + "|" + passwordInputField.text);
            RefreshInputField();
        });
        goLoginButton.onClick.AddListener(() =>
        {
            goLoginButton.gameObject.SetActive(false);
            registerButton.gameObject.SetActive(false);

            goRegisterButton.gameObject.SetActive(true);
            loginButton.gameObject.SetActive(true);

            RefreshInputField();
            passwordRetypeInputField.gameObject.SetActive(false);
        });
        goRegisterButton.onClick.AddListener(() =>
        {
            goRegisterButton.gameObject.SetActive(false);
            loginButton.gameObject.SetActive(false);

            goLoginButton.gameObject.SetActive(true);
            registerButton.gameObject.SetActive(true);

            RefreshInputField();
            passwordRetypeInputField.gameObject.SetActive(true);
        });
    }

    private void OnApplicationQuit()
    {
        
    }
}
